package com.example.demo.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.example.demo.dao.StudentMapper;
import com.example.demo.entity.Student;
import com.example.demo.service.StudentService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service
public class StudentServiceImpl implements StudentService {

    @Resource
    private StudentMapper costMapper;

    @Override
    public void insert(Student student) {
        System.out.println("insert:" + costMapper.insert(student));
    }

    @Override
    public void insert2(Student student) {
        System.out.println("insert2:" + costMapper.insert(student));
    }

    @Override
    public Student query1(Integer id) {
        return costMapper.selectById(id);
    }

    @Override
    public Student query2(Integer id) {
        return costMapper.selectById(id);
    }

    @Override
    public PageInfo<Student> queryPage() {
        Page<Student> page = PageHelper.startPage(1, 10, true);
        page.setOrderBy("id desc");

        Wrapper<Student> wrapper = new EntityWrapper();
        List<Student> list = costMapper.selectList(wrapper);

        PageInfo<Student> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

}